const mongoose = require('mongoose');
const { v4: uuidv4 } = require('uuid');

const roleMenuSchema = new mongoose.Schema({
    id: {
        type: String,
        required: true,
        unique: true,
        default: () => uuidv4(),
        description: 'id'
    },
    role_id: {
        type: String,
        required: [true, '角色ID必填'],
        ref: 'Role',
        description: '角色ID'
    },
    menu_id: {
        type: String,
        required: [true, '菜单ID必填'],
        ref: 'Menu',
        description: '菜单ID'
    }
}, {
    timestamps: true,
    versionKey: false
});

// 创建复合索引
roleMenuSchema.index({ role_id: 1, menu_id: 1 }, { unique: true });

module.exports = mongoose.model('RoleMenu', roleMenuSchema); 